<?php
/**
 * @author wyl
 * @date 2015-8-26 11:15:29
 */
Yii::import('system.web.widgets.CWidget');
class CAddWatchList extends CWidget{
	public $label;
	public $url;
		
	public function init(){
		$this->label=(empty($this->label))?'Add it To Watch List':$this->label;	
	}
	
	public function run(){
		$this->renderButton();
		$this->addScript();
	}
	
	public function renderButton(){
		echo CHtml::htmlButton($this->label,array(
			'class'	=>'btn btn-default btn-watch-list add-watch-list',
		));
	}
	
	public function addScript(){
		Yii::app()->clientScript->registerScript('add-watch-list-js',"
			$(document).ready(function(){
				$(document).on('click','.add-watch-list',function(){
					$('.add-watch-list').each(function(){
						$(this).html('Remove');
						$(this).removeClass('add-watch-list').addClass('delete-watch-list');
					})
				});
				$(document).on('click','.delete-watch-list',function(){
					$('.delete-watch-list').each(function(){
						$(this).html('Add it To Watch List');	
						$(this).removeClass('delete-watch-list').addClass('add-watch-list');
					})
				});
			})
		");
		Yii::app()->clientScript->registerCss('add-watch-list-css', "
			.btn.btn-watch-list{
				font-size:16px;
				font-weight:700;
				padding-left:20px;
				padding-right:20px;	
			}	
		");
	}
}		
